Remove spaces from keysΒΆ
Remove spaces from Dictionary keys.
DOL = {'S 001': ['Math', 'Science'],
'S 002': ['Math', 'English'],
}
print("Original dictionary: ", DOL)
student_dict = {k.translate({32: None}): v for k, v in DOL.items()}
print("New dictionary: ", student_dict)
Output:
Original dictionary: {'S 002': ['Math', 'English'], 'S 001': ['Math', 'Science']}
New dictionary: {'S001': ['Math', 'Science'], 'S002': ['Math', 'English']}